package aooO.crm.Controller;

import aooO.crm.Service.ActivityRemarkService;
import aooO.crm.common.Utils.DateUtils;
import aooO.crm.common.Utils.UUIDUtils;
import aooO.crm.pojo.ActivityRemark;
import aooO.crm.pojo.User;
import aooO.crm.pojo.returnObject;
import aooO.crm.pojo.stateCode;
import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;

@Controller
@RequestMapping("workbench/activity")
public class activityRemarkController {

    @Autowired
    ActivityRemarkService activityRemarkService;


//    '/saveCreateActivityRemark.do'
    @RequestMapping("/saveCreateActivityRemark.do")
    @ResponseBody
    public Object saveCreateActivityRemark(ActivityRemark activityRemark, HttpSession session){
//        noteContent:noteContent,
//        activityId:activityId
        returnObject msg=new returnObject(stateCode.STATE_FAILURE,"");
        activityRemark.setId(UUIDUtils.uuid());
        activityRemark.setCreateTime(DateUtils.FormatDateTime(new Date()));
        User user =(User) session.getAttribute(stateCode.SESSION_USER);
        activityRemark.setCreateBy(user.getId());
        activityRemark.setEditFlag(stateCode.STATE_FAILURE);
      try{
        int i = activityRemarkService.insertActivityRemark(activityRemark);
        if (i>0){
            msg.setCode(stateCode.STATE_SUCCESS);
            msg.setReturnData(activityRemark);
        }else {
            msg.setMessage("留言失败！");
        }
      }catch (Exception e){
            msg.setMessage("留言失败！");
        }
        return msg;
    }


//    workbench/activity/deleteActivityRemarkById.do
    @RequestMapping("/deleteActivityRemarkById.do")
    @ResponseBody
    public Object deleteActivityRemarkById(String id){
        returnObject msg=new returnObject(stateCode.STATE_FAILURE,"");
        try{
            int i = activityRemarkService.deleteActivityRemarkById(id);
            if (i>0){
                msg.setCode(stateCode.STATE_SUCCESS);
            }else{
                msg.setMessage("删除失败！");
            }
        }catch (Exception e){
            msg.setMessage("删除失败！");
        }

        return msg;
    }


//    workbench/activity/saveEditActivityRemark.do
    @RequestMapping("/saveEditActivityRemark.do")
    @ResponseBody
    public Object saveEditActivityRemark(ActivityRemark activityRemark,HttpSession session){
        returnObject msg=new returnObject(stateCode.STATE_FAILURE,"");
        activityRemark.setEditFlag(stateCode.STATE_SUCCESS);
        User user =(User) session.getAttribute(stateCode.SESSION_USER);
        activityRemark.setEditBy(user.getId());
        activityRemark.setEditTime(DateUtils.FormatDateTime(new Date()));
        try{
            int i = activityRemarkService.updateActivityRemark(activityRemark);
            if (i>0){
                msg.setCode(stateCode.STATE_SUCCESS);
                msg.setReturnData(activityRemark);
            }else{
                msg.setMessage("更新失败！");
            }
        }catch (Exception e){
            msg.setMessage("更新失败！");
        }
        return msg;
    }



}
